package cn.tedu._05weibo.common.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 统一响应结果的Java
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer code;
    private String msg;
    private  Object data;
    /**
     * 1.构造方法：针对有具体数据返回的controller方法
     */
    public JsonResult(StatusCode statusCode, Object data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }
    /**
     * 2.构造方法：针对于没有具体数据返回的controller方法;
     */
    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();

    }
    public static JsonResult ok(Object data){
        return  new JsonResult(StatusCode.OPERATION_SUCCESS,data);

    }
    public static JsonResult ok(){
        return  ok(null);
    }



}
